Skip to content

Comments

Throw correct IllegalArgumentException from WolfCryptRandom.engineGenerateSeed()#152

Merged
rlm2002 merged 1 commit intowolfSSL:masterfrom
cconlon:jceRngArgCheck
Sep 8, 2025
Merged

Throw correct IllegalArgumentException from WolfCryptRandom.engineGenerateSeed()#152
rlm2002 merged 1 commit intowolfSSL:masterfrom
cconlon:jceRngArgCheck

Conversation

@cconlon
Copy link
Member

@cconlon cconlon commented Sep 4, 2025

This PR correctly throws IllegalArgumentException from WolfCryptRandom.engineGenerateSeed() for input values that are negative or larger than wolfCrypt's supported size.

This also adds algorithm aliases (Hash_DRBG, DRBG) to match the existing HashDRBG implementation. This allows for better interop for applications using those other algorithm names.

JUnit tests are included to prevent regression on these changes.

This fixes OpenJDK SunJCE test: security/SecureRandom/EnoughSeedTest.java

@cconlon cconlon self-assigned this Sep 4, 2025
@cconlon cconlon requested a review from Copilot September 4, 2025 16:30
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR enhances the WolfCryptRandom implementation by adding proper input validation to engineGenerateSeed() and introducing algorithm aliases for better interoperability. The changes ensure that negative values and values exceeding wolfCrypt's maximum block length properly throw IllegalArgumentException, which fixes compatibility with OpenJDK SunJCE tests.

  • Added input validation to throw IllegalArgumentException for invalid seed generation parameters
  • Introduced algorithm aliases (Hash_DRBG, DRBG) to match existing HashDRBG implementation
  • Added comprehensive JUnit tests to prevent regression

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/main/java/com/wolfssl/provider/jce/WolfCryptRandom.java Added input validation and logging to engineGenerateSeed() method
src/main/java/com/wolfssl/provider/jce/WolfCryptProvider.java Registered new algorithm aliases for SecureRandom
src/main/java/com/wolfssl/wolfcrypt/Rng.java Added static constant for maximum block length
jni/jni_rng.c Refactored error handling and added native method for max block length
jni/include/com_wolfssl_wolfcrypt_Rng.h Added JNI header for new native method
src/test/java/com/wolfssl/provider/jce/test/WolfCryptRandomTest.java Added comprehensive tests for new validation and aliases
README_JCE.md Updated documentation to reflect new algorithm aliases

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

…neGenerateSeed(), add HashDRBG aliases Hash_DRBG and DRBG
@cconlon cconlon assigned rlm2002 and unassigned cconlon Sep 5, 2025
@rlm2002 rlm2002 merged commit 2fd62a2 into wolfSSL:master Sep 8, 2025
46 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants